package com.mm.girl.service.impl;

import com.mm.girl.entity.ImageUrl;
import com.mm.girl.entity.Mp4Url;
import com.mm.girl.service.DataService;
import com.mm.girl.util.MyUtil;
import com.mm.girl.util.UrlUtil;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Connection;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 * @author 周港
 */
@Service
@Slf4j
public class DataServiceImpl implements DataService {

    private static final Random RANDOM = new Random();
    private static final String MP4_DATA_SOURCE_URL = "http://xjj.jmwpower.top/get/get";
    /**
     * 源
     */
    private static final String[] DEFAULT_ADDRESS = new String[]{"1", "2", "3", "4", "5"};
    private static final String[] KUAISHOU_ADDRESS = new String[]{"6"};
    private static final String[] TIKTOK_ADDRESS = new String[]{"7"};
    private static final String[] FULI_ADDRESS = new String[]{"8"};
    private static final String[] SEX_ADDRESS = new String[]{"9", "10", "11", "12", "13", "14"};

    @Override
    public Mp4Url getMp4Url(String source) {
        Mp4Url mp4Url = new Mp4Url();
        String url = "";
        if (source != null && !"".equals(source)) {
            String[] split = source.split(",");
            int i = RANDOM.nextInt(split.length);
            url = MP4_DATA_SOURCE_URL + split[i] + ".php";
        } else {
            int i = RANDOM.nextInt(DEFAULT_ADDRESS.length);
            url = MP4_DATA_SOURCE_URL + DEFAULT_ADDRESS[i] + ".php";
        }
        mp4Url.setDataSourceUrl(url);
        mp4Url.setUid(MyUtil.getUid());
        Connection.Response execute = UrlUtil.getExecute(url);
        return execute == null ? mp4Url.setMp4Url("") : mp4Url.setMp4Url(execute.body());
    }

    @Override
    public ImageUrl getImageUrl() {
        return null;
    }

}
